<?php



namespace app\backend\controller;



class Index extends Admin

{

	

    public function index(){




        $notice_no=\app\api\model\Notice::where("status=0")->count();

		$this->view->assign('menus',$this->getSubMenu(0));

        $this->view->assign('notice_no',$notice_no);

        $menu=$this->getSubMenu(0);

    

		return view('index');

    }

	

	

	public function main(){

		return view('main');

	}

	

	

	//生成左侧菜单栏结构列表 递归的方法

	public function getSubMenu($pid){

		$list = db("menu")->where(['status'=>1,'app_id'=>209,'pid'=>$pid])->order('sortid asc')->select()->toArray();

		if($list){

			$menus = [];

			foreach($list as $key=>$val){

				$sublist = db("menu")->where(['status'=>1,'app_id'=>209,'pid'=>$val['menu_id']])->order('sortid asc')->select()->toArray();

				if($sublist){

					$menus[$key]['sub'] = $this->getSubMenu($val['menu_id']);

				}

				$menus[$key]['title'] = $val['title'];

				$menus[$key]['icon'] = !empty($val['menu_icon']) ? $val['menu_icon'] : 'fa fa-clone';

				$menus[$key]['url'] = !empty($val['url']) ? (strpos($val['url'], '://') ? $val['url'] : url($val['url'])) : url('backend/'.str_replace('/','.',$val['controller_name']).'/index');

				$menus[$key]['access_url'] = !empty($val['url']) ? $val['url'] :  'backend/'.str_replace('/','.',$val['controller_name']);

			}

			return $menus;

		}	

	}

	

	

}

